package com.star.controller.user;

import com.star.dto.BusinessPageQueryDTO;
import com.star.entity.Business;
import com.star.result.PageResult;
import com.star.result.Result;
import com.star.service.BusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("userBusinessController")
@RequestMapping("/user/business")
@Slf4j
@Api(tags = "C端商家相关接口")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    /**
     * 商家分页查询
     * @param businessPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("商家分页查询")
    public Result<PageResult> page(BusinessPageQueryDTO businessPageQueryDTO){
        log.info("商家分页查询{}", businessPageQueryDTO);
        PageResult pageResult = businessService.userPageQuery(businessPageQueryDTO);
        return Result.success(pageResult);
    }
    /**
     * 根据id查询商家信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询商家信息")
    public Result<Business> getById(@PathVariable Long id){
        log.info("商家id{}", id);
        Business business = businessService.getById(id);
        return Result.success(business);
    }
}
